#define _CRT_SECURE_NO_WARNINGS 1
#include <string>
using namespace std;
class Solution {
public:
    string truncateSentence(string s, int k)
    {
        int count = 0;
        int i = 0;
        for (;i < s.size();i++)
        {
            if (s[i] == ' ')
            {
                ++count;
                if (count == k) break;
            }
        }
        if (i == s.size()) ++i;
        return s.substr(0, i);
    }
};